from playwright.sync_api import Page, BrowserContext, Browser

from model.ProConfModel import ProConfModel
from service.KeepAliveService import get_storage_path_by_pro, need_login, set_keep_alive_storage
from tools.Result import error_result
from service.BaseService import BaseService
from service.tjyz.detail import get_html_detail
from service.tjyz.login import login_with_slide


class TjyzService(BaseService):
    def __init__(self):
        super().__init__()
    def execute(self, browser: Browser, context:BrowserContext,pro_config: ProConfModel, detail_url: str):

        page = context.new_page()

        if need_login(pro_config):
            res = login_with_slide(page, pro_config)
            if res == False:
                return error_result("登录异常")
            set_keep_alive_storage(pro_config, context)

        return get_html_detail(page,detail_url)